//
//  NSString+Category.m
//  年輕時代的睡神
//
//  Created by 劉裕 on 25/3/2016.
//  Copyright © 2016年 劉裕. All rights reserved.
//

#import "NSString+Category.h"

@implementation NSString (Category)

- (CGSize)sizeWithFont:(UIFont *)font maxW:(CGFloat)maxW {
    NSMutableDictionary *attritubes = [NSMutableDictionary dictionary];
    attritubes[NSFontAttributeName] = font;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attritubes context:nil].size;
}

- (CGSize)sizeWithFont:(UIFont *)font {
    return [self sizeWithFont:font maxW:MAXFLOAT];
}

+ (NSString *)document {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

+ (NSString *)dateString {
    NSDateFormatter *fmt = [NSDateFormatter new];
    fmt.dateFormat = @"yyyyMMddHHmmss";
    return [fmt stringFromDate:[NSDate date]];
}

@end